<?php
if ( !defined('IN_ADMINCP') || !defined('IN_SEC') ){
	exit('Access Denied.');
}

$adminid = $admincp->adminid;
$group = $admincp->groups[$admincp->admin['groupid']];

$id = abs(intval($_G['gp_id']));

$ids = $_G['gp_ids'];

if( $ids ){
	if( !$admincp->manage ){
		$admincp->cpmsg('Access Faild.');
	}
	$where = array();
	$cida = explode(',', $ids);
	redirect();
}

if( !$ids && $id && !$customer = fetch('customer', $id) ){
	$admincp->cpmsg('客户不存在');
}

if( $customer ){
	if( !$admincp->manage && $adminid != $customer['adminid'] ){
		$admincp->cpmsg('您无权操作');
	}
	$team = fetch('team', $customer['id'], 'customerid');
	if( $team ){
		$admincp->cpmsg('该客户有未删除的项目：' . $team['name']);
	}
	delete('customer', $customer['id']);
	delete('customer_contacts', $customer['id'], 'customerid');
	delete('customer_demands', $customer['id'], 'customerid');
	$admincp->log('customer', $customer['id'], '删除客户：' . $customer['name'], 'delete');
	Session::Set('notice', '操作成功');
	$admincp->json_type('refresh');
	$admincp->success();
}
?>